#ifndef SCANNERCONTROL_H
#define SCANNERCONTROL_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <QByteArray>
#include <QStringList>
#include <QThread>
#include <QMutex>

class ScannerControl : public QObject
{
    Q_OBJECT

    Q_PROPERTY(int Current_QR_Type READ Current_QR_Type WRITE setCurrent_QR_Type NOTIFY Current_QR_TypeChanged FINAL)

public:
    // 删除拷贝构造函数和赋值运算符，防止复制
    ScannerControl(const ScannerControl&) = delete;
    ScannerControl& operator=(const ScannerControl&) = delete;

    // 获取单例实例
    static ScannerControl* getInstance(QObject *parent = nullptr);

    // 设置Modbus连接参数
    void setScannerConnectParameter(QString serialPort,
                                    QString baudRate,
                                    QString dataBit,
                                    QString parityBit,
                                    QString stopBit);

    // 连接Modbus设备
    void connectToDevice();

    // 扫码枪串口对象
    QSerialPort* m_Scanner;

    int Current_QR_Type() const;
    void setCurrent_QR_Type(int newCurrent_QR_Type);

signals:

    // 离线料单信号
    void send_Scanner_Result_OutLine_Signal(const QByteArray& result);


    void send_Scanner_Result_SuZhi_Signal(const QByteArray& result);

    void send_Scanner_Result_ChangFeng_Signal(const QByteArray& result);

    void send_Scanner_Result_XinGeEr_Signal(const QByteArray& result);

    void send_Scanner_Result_ChuangPin_Signal(const QByteArray& result);

    void Current_QR_TypeChanged();

public slots:

    void read_Scanner_Result_Slots();

private:
    // 私有构造函数，防止外部创建实例
    ScannerControl(QObject *parent = nullptr);
    ~ScannerControl();

    // 静态实例指针
    static ScannerControl* m_instance;
    // 互斥锁，确保线程安全
    static QMutex m_mutex;
    int m_Current_QR_Type;
};

#endif // SCANNERCONTROL_H
